<?php

namespace Rebecca\RebeccaBundle\Component;

use Doctrine\ORM\EntityManager;

/**
 * Description of ComponentBase
 *
 * @author JeyDotC
 */
abstract class ComponentBase {

    /**
     *
     * @var EntityManager
     */
    protected $em;
    protected $entityName;

    function __construct($entityName, EntityManager $entityManager) {
        $this->entityName = $entityName;
        $this->em = $entityManager;
    }

    function save($entity) {
        $this->em->persist($entity);
    }

    function update($entity) {
        $this->em->persist($entity);
    }

    function delete($entity) {
        $this->em->remove($entity);
    }

    function getAll() {
        return $this->em->getRepository($this->entityName)->findAll();
    }

    function get($id) {
        return $this->em->find($this->entityName, $id);
    }
    
    public function commit() {
        $this->em->flush();
    }


    function getEntityName() {
        return $this->entityName;
    }
}

?>
